package com.xuhai.blog19.api;

import com.xuhai.blog19.admin.entity.ArticleEntity;
import com.xuhai.blog19.admin.service.ArticleService;
import com.xuhai.blog19.admin.service.BannerService;
import com.xuhai.blog19.admin.service.CategoryService;
import com.xuhai.blog19.admin.service.WebsiteService;
import com.xuhai.blog19.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author PangJunjie
 * @Date 2023/2/9/009
 */
@RestController
@RequestMapping("/api")
public class ApiIndexController {
    @Autowired
    private WebsiteService websiteService;
    @Autowired
    private BannerService bannerService;
    @Autowired
    private ArticleService articleService;
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/website")
    public R website() {
        return R.ok().data(websiteService.getById(1));
    }

    @GetMapping("/banner")
    public R banner() {
        return R.ok().data(bannerService.getListByType(1));
    }

    @GetMapping("/href")
    public R href() {
        return R.ok().data(bannerService.getListByType(2));
    }

    @GetMapping("/total")
    public R total() {
        ArticleEntity article = new ArticleEntity();
        article.setArticleStatus(1);
        article.setStatus(1);
        Map<String, Integer> map = new HashMap<>();
        map.put("articleCount", articleService.getCount(article));
        map.put("categoryCount", categoryService.getCount(1));
        return R.ok().data(map);
    }

}
